// team.js
var app = getApp();
import LoadMore from '../../../utils/LoadMore.js'
var util = require('../../../utils/util.js')
var load = new LoadMore;

Page({
    data: {
        level: 1,
        currentPage: 1,
        teamMember: null,
        url:app.globalData.setting.url
    },

    onLoad: function (options) {
        load.init(this, '', 'teamMember');
        this.getTeamList();
    },

    changeTab: function (e) {
        this.setData({ level: e.currentTarget.dataset.id });
        this.reloadGoodList();
    },

    getTeamList: function () {
        var that = this;
        var requestUrl = '/api/Distribut/lower_list?level=' + that.data.level +'&p=' + that.data.currentPage;
        load.request(requestUrl, function (res) {
            that.data.currentPage++;
            if (res.data.result){
                res.data.result.forEach(function (val, index, arr) {
                val.regTime = util.format(val.reg_time, 'yyyy-MM-dd');
              });
            }
            wx.stopPullDownRefresh();
        });
    },

    onPullDownRefresh: function () {
        this.reloadGoodList();
    },

    //重置数据
    reloadGoodList: function () {
        load.resetConfig();
        this.data.teamMember = null;
        this.data.currentPage = 1;
        this.getTeamList();
    },

    onReachBottom: function () {
        if (load.canloadMore()) {
            this.getTeamList();
        }
    },

})